package com.hh.generator.common.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;

public class TableToClassConvertUtil {

    public static String className(String prefix, String tableName) {
        String name = tableName;
        if (StringUtils.isNotBlank(prefix)) {
            name = tableName.substring(prefix.length());
        }
        return capitalizeFully(name);
    }

    public static String infoClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Info";
    }

    public static String mapperClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Mapper";
    }

    public static String converterClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Converter";
    }

    public static String enumClassName(String prefix, String tableName, String columnName) {
        return className(prefix, tableName + "_" + columnName) + "Enum";
    }

    public static String serviceClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Service";
    }

    public static String serviceImplClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "ServiceImpl";
    }

    public static String facadeClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Feign";
    }

    public static String facadeImplClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "FeignImpl";
    }

    public static String controllerClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "Controller";
    }

    public static String addRequestClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "AddRequest";
    }

    public static String updateRequestClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "UpdateRequest";
    }

    public static String queryRequestClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "QueryRequest";
    }

    public static String addResponseClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "AddResponse";
    }

    public static String updateResponseClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "UpdateResponse";
    }

    public static String deleteResponseClassName(String prefix, String tableName) {
        return className(prefix, tableName) + "DeleteResponse";
    }

    public static String fieldName(String columnName) {
        return StringUtils.uncapitalize(capitalizeFully(columnName));
    }


    public static String capitalizeFully(String value) {
        return WordUtils.capitalizeFully(value, new char[]{'_'}).replace("_", "");
    }
}
